package demo1;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Controller;
import org.springframework.stereotype.Repository;
import org.springframework.stereotype.Service;

@Component
//@Repository
//@Service
//@Controller
public class User {
    //@Value注解如果定义在属性上,Spring容器在创建对象时,会为该属性赋值
    //@Value("张三")
    private String name;
    //@Value("18")
    private int age;
    public void sayHello(){
        System.out.println("hello");
    }

    @Override
    public String toString() {
        return "User{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }

    public String getName() {
        return name;
    }

    //@Value注解也可以在属性对应的set方法上标注,用于为对应的属性初始化
    @Value("张三")
    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    @Value("18")
    public void setAge(int age) {
        this.age = age;
    }
}
